<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>父组件获取子组件的数据</title>
</head>

<body>
    <div>
        父子组件通讯：父组件获取子组件的数据，是由子组件主动发送数据，父组件接收数据
    </div>
    <div id="app">
        <aaa></aaa>
    </div>
    <template id="a">
        <div>
            <h2>我是aaa组件->{{msg}}</h2>
            <bbb v-on:child-message="get"></bbb>
        </div>
    </template>
    <template id="b">
        <div>
            <h3>我是组件bbb->{{m}}</h3>
            <button v-on:click="send">发送数据到aaa</button>
        </div>
    </template>
    <script src="node_modules/vue/dist/vue.js"></script>
    <script>
        var vm = new Vue({
            el: '#app',
            components: {
                'aaa': {
                    template: '#a',
                    data: function () {
                        return {
                            msg: "我是组件aaa的数据"
                        }
                    },
                    methods: {
                        get: function (msg) {
                            this.msg = msg;
                        }
                    },
                    components: {
                        'bbb': {
                            template: '#b',
                            data: function () {
                                return {
                                    m: "我是组件bbb的数据"
                                }
                            },
                            methods: {
                                send() {
                                    //vm.$emit(时间名，数据)
                                     this.$emit('child-message', this.m)
                                }
                            }

                        }
                    }
                }
            }
        });
    </script>
</body>

</html>